package com.sbj.controller;

import cn.hutool.core.convert.Convert;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sbj.dto.req.DivisionReq;
import com.sbj.dto.res.DivisionRes;
import com.sbj.entity.Division;
import com.sbj.service.DivisionService;
import com.zmh.framework.config.BaseCommonInterface;

import com.zmh.framework.util.Result;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * @author summer
 * @version 1.0
 * @date 2024/8/27 15:26
 */
@RestController
@RequestMapping(value = "/division")
@AllArgsConstructor
public class DivisionController implements BaseCommonInterface<DivisionReq, DivisionRes> {

    private final DivisionService divisionService;


    @Override
    public Result<String> save(@Valid DivisionReq divisionReq) {
        divisionService.saveOrUpdate(Convert.convert(Division.class, divisionReq));
        return Result.successResult();
    }

    @Override
    public Result<String> del(Integer id) {
        divisionService.removeById(id);
        return Result.successResult();
    }

    @Override
    public Result<Page<DivisionRes>> lists(DivisionReq divisionReq) {
        return Result.successResult(divisionService.lists(divisionReq));
    }

    @Override
    public Result<DivisionRes> findById(Integer id) {
        return Result.successResult(Convert.convert(DivisionRes.class,divisionService.getById(id)));
    }

    @Override
    public Result<String> batchDel(List<DivisionRes> list) {
        return null;
    }
}
